package com.wanmait.hotelManage.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.wanmait.hotelManage.util.DBHelper;
import com.wanmait.hotelManage.vo.NewsCommentReport;
import com.wanmait.hotelManage.vo.Userinfo;

public class messageDAO {
   private messageDAO() {
	   
   }
   public static messageDAO messageDAO=new messageDAO();
   public static messageDAO getDAO() {
	   
	   return messageDAO;
   } 
  public List<NewsCommentReport> getnewsCommentReports() {
  	  Connection conn=null;
  	  PreparedStatement ps=null;
  	  ResultSet rs=null;
  	List <NewsCommentReport>newsCommentReports=null;
  	  StringBuilder sb=new StringBuilder();
  	  sb.append(" SELECT * FROM news_comment_report,userinfo WHERE news_comment_report.userinfo_id=userinfo.id")
  	  .append(" AND news_comment_report.ok=1");
  	  String sql=sb.toString();
  	  try {
  		newsCommentReports=new ArrayList<NewsCommentReport>();
  		conn=DBHelper.getDBHelper().getConn();
  		ps=conn.prepareStatement(sql);
  		rs=ps.executeQuery();
  		while(rs.next()) {
  		Userinfo userinfo=new Userinfo();
  		NewsCommentReport newsCommentReport=new NewsCommentReport();
  		userinfo.setEnable(rs.getBoolean("userinfo.enable"));
		userinfo.setGender(rs.getBoolean("gender"));
		userinfo.setId(rs.getInt("userinfo.id"));
		userinfo.setInputTime(rs.getTimestamp("input_time"));
		userinfo.setPassword(rs.getString("password"));
		userinfo.setPic(rs.getString("pic"));
		userinfo.setTelephoneNumber(rs.getString("telephone_number"));
		userinfo.setUsername(rs.getString("username"));
		newsCommentReport.setId(rs.getInt("news_comment_report.id"));
		newsCommentReport.setInputTime(rs.getTimestamp("news_comment_report.input_time"));
		
		newsCommentReport.setOk(rs.getBoolean("ok"));
		newsCommentReport.setRead(rs.getBoolean("read"));
		newsCommentReport.setUserinfo(userinfo);
		newsCommentReports.add(newsCommentReport);
  		}
  	   
	} catch (Exception e) {
		// TODO: handle exception
	}
  	  return newsCommentReports;
  } 
   
   
   
}
